#include "Market.hpp"

namespace StockMarket
{
    void Stock::updatePrice(const int new_price)
    {
        if (new_price != m_old_price)
        {
            for (auto &etf : m_etfs)
            {
                if (auto p = etf.lock())
                {
                    p->updateIOPV(m_stock_code, m_old_price, new_price);
                }
            }
        }

        m_old_price = new_price; // 必须要先更新IOPV，然后再更新价格
    }
    int Stock::getPrice() const
    {
        return m_old_price;
    }
    void Stock::addETF(std::weak_ptr<ETF> etf)
    {
        m_etfs.push_back(etf);
    }

} // namespace StockMarket